library(pscl)
library(car)
library(effects)
library(lmtest)
library(stargazer)
library(multiwayvcov)

#laptop
setwd('/Users/joelsievert/Dropbox/Research/Electoral Institutions/DRDR/journal submissions/JPIPE/final submission/Replication Materials')


m <- read.csv('jpipe_tab2.csv')



###################
##model estiamtes##
###################

m1 <- lm(cs1 ~ dpresC + mfg.pc + forgn.p +  urb.p, m)
m2 <- lm(cs1 ~ dpresC*senator + mfg.pc + forgn.p +  urb.p, m)
#F test to compare model with and without interaction
anova(m1, m2)

m3 <- lm(cs1 ~ dem_avgC + mfg.pc + forgn.p +  urb.p, m)
m4 <- lm(cs1 ~ dem_avgC*senator + mfg.pc + forgn.p +  urb.p, m)
anova(m3, m4)

m5 <- lm(cs1 ~ dem_jointC + mfg.pc + forgn.p +  urb.p, m)
m6 <- lm(cs1 ~ dem_jointC*senator + mfg.pc + forgn.p +  urb.p, m)
anova(m5, m6)


o1 <- coeftest(m1, vcov = cluster.vcov(m1, cluster = m$state_year))
o2 <- coeftest(m2, vcov = cluster.vcov(m2, cluster = m$state_year))
o3 <- coeftest(m3, vcov = cluster.vcov(m3, cluster = m$state_year))
o4 <- coeftest(m4, vcov = cluster.vcov(m4, cluster = m$state_year))
o5 <- coeftest(m5, vcov = cluster.vcov(m5, cluster = m$state_year))
o6 <- coeftest(m6, vcov = cluster.vcov(m6, cluster = m$state_year))

stargazer(o1, o2, o3, o4, o5, o6, digits = 2)

stargazer(m1, m2, m3, m4, m5, m6, digits = 2)

###############
###CHOW TEST###
###############



m1 <- lm(cs1 ~ dpresC + mfg.pc + forgn.p +  urb.p, m)
m2 <- lm(cs1 ~ dpresC + mfg.pc + forgn.p +  urb.p + senator/( + dpresC + mfg.pc + forgn.p +  urb.p), m)
anova(m1, m2)

m1 <- lm(cs1 ~ dem_avgC + mfg.pc + forgn.p +  urb.p, m)
m2 <- lm(cs1 ~ dem_avgC + mfg.pc + forgn.p +  urb.p + senator/( + dem_avgC + mfg.pc + forgn.p +  urb.p), m)
anova(m1, m2)

m1 <- lm(cs1 ~ dem_jointC + mfg.pc + forgn.p +  urb.p, m)
m2 <- lm(cs1 ~ dem_jointC + mfg.pc + forgn.p +  urb.p + senator/( + dem_jointC + mfg.pc + forgn.p +  urb.p), m)
anova(m1, m2)



